home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C08 / Mutable.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  467 b   |  27 lines

  1. //: C08:Mutable.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // The "mutable" keyword
  7.  
  8. class Z {
  9.   int i;
  10.   mutable int j;
  11. public:
  12.   Z();
  13.   void f() const;
  14. };
  15.  
  16. Z::Z() { i = j = 0; }
  17.  
  18. void Z::f() const {
  19. //! i++; // Error -- const member function
  20.     j++; // OK: mutable
  21. }
  22.  
  23. int main() {
  24.   const Z zz;
  25.   zz.f(); // Actually changes it!
  26. } ///:~
  27.